sele 1
F1='ACT_PROC'
SET EXCLU OFF
USE &DR&F1
sele 2
F2='ACT_PRO1.DBF'
SET EXCLU OFF
USE &DR&F2
SELE 1
APPEN FROM &DR&F2 FOR INV_NBER=NOFT
FILM='ME'+kdpat+'.dbf'
F8='MEDICAL'
SELE 8
SET EXCLU OFF
USE &DR&F8
COPY STRU TO &DR&FILM
USE
SET EXCLU OFF
USE &DR&FILM
APPEN FROM &DR&F2 FOR INV_NBER=NOFT
COUNT TO NPROC
NBER=VAL(VISIT_NBER)+1
NOBER=STR(NBER,5)
GO TOP
DO WHILE .NOT. EOF()
   ARKOD=AREA_CODE
   SUKOD=SUB_AREACO
   PRKOD=PRO_CODE
   F9='DOCT_FE1'
   SELE 9
   SET EXCLU OFF
   USE &DR&F9
   GO TOP
   LOCAT FOR AREA_CODE=ARKOD .AND. SUB_AREACO=SUKOD .AND. PRO_CODE=PRKOD .AND. INV_NBER=NOFT
   DOCFE=DOC_FEE
   DOCNM=DOC_ALIAS
   IF FOUND()
      SELE 8
      IF REC_LOCK()
         REPL COST_ALLO1 WITH DOCFE
         REPL DOC_ALIAS WITH DOCNM
      ENDIF
      UNLOCK
      SKIP
   ELSE
      SELE 8
      SKIP
   ENDIF
ENDDO
SELE 9
USE

sele 1
F1='ACT_PHAR'
SET EXCLU OFF
USE &DR&F1
sele 2
F2='ACT_PHA1.DBF'
SET EXCLU OFF
USE &DR&F2
SELE 1
APPEN FROM &DR&F2 FOR INV_NBER=NOFT

FILP='PH'+kdpat+'.dbf'
F8='PHARMACY'
SELE 8
SET EXCLU OFF
USE &DR&F8
COPY STRU TO &DR&FILP
USE
SET EXCLU OFF
USE &DR&FILP
APPEN FROM &DR&F2 FOR INV_NBER=NOFT
USE &DR&FILP
GO TOP
DO WHILE .NOT. EOF()
   KDPHAR=PHAR_CODE
   NMPHAR=SPACE(16)
   IF SUBSTR(KDPHAR,2,1)='6' .OR. SUBS(KDPHAR,2,1)='7' .OR. SUBSTR(KDPHAR,2,1)='9'
      F9='DISPOS'
      SELE 9
      USE &DR&F9 INDEX &DR&F9
      SEEK KDPHAR
      IF .NOT. EOF()
         NMPHAR=DISP_NAME
      ENDIF
   ELSE
      F9='DRUGS'
      SELE 9
      USE &DR&F9 INDEX &DR&F9
      SEEK KDPHAR
      IF .NOT. EOF()
         NMPHAR=DRUG_NAME
      ENDIF
   ENDIF
   SELE 8
   IF REC_LOCK()
      REPL PHAR_NAME WITH NMPHAR
   ENDIF
   UNLOCK
   SKIP
ENDDO


sele 1
F1='REVENUE'
SET EXCLU OFF
USE &DR&F1
sele 2
F2='REVENUE1.DBF'
SET EXCLU OFF
USE &DR&F2
SELE 1
APPEN FROM &DR&F2 FOR INV_NBER=NOFT

sele 1
F1='ACTIVITY'
SET EXCLU OFF
USE &DR&F1
sele 2
F2='ACTIVIT1.DBF'
SET EXCLU OFF
USE &DR&F2
SELE 1
APPEN FROM &DR&F2 FOR INV_NBER=NOFT

sele 1
F1='DOCT_FEE'
SET EXCLU OFF
USE &DR&F1
sele 2
F2='DOCT_FE1.DBF'
SET EXCLU OFF
USE &DR&F2
SELE 1
APPEN FROM &DR&F2 FOR INV_NBER=NOFT

SELE 1
F1='ACT_PROC'
SET EXCLU OFF
USE &DR&F1
SELE 2
F2='ACT_PHAR'
SET EXCLU OFF
USE &DR&F2
SELE 4
F4='REVENUE'
SET EXCLU OFF
USE &DR&F4
SELE 5
F5='ACTIVITY'
SET EXCLU OFF
USE &DR&F5
SELE 6
F6='DOCT_FEE'
SET EXCLU OFF
USE &DR&F6

SELE 1
LOCA FOR INV_NBER=NOFT
DO WHILE .T.
   IF FOUND() .AND. .NOT. EOF()
      IF REC_LOCK()
         REPL INV_STAT WITH 'CR'
      ENDIF
      UNLOCK
      CONTINUE
      LOOP
   ELSE
      EXIT
   ENDIF
ENDDO

SELE 2
LOCA FOR INV_NBER=NOFT
DO WHILE .T.
   IF FOUND() .AND. .NOT. EOF()
      IF REC_LOCK()
         REPL INV_STAT WITH 'CR'
      ENDIF
      UNLOCK
      CONTINUE
      LOOP
   ELSE
      EXIT
   ENDIF
ENDDO

SELE 4
LOCA FOR INV_NBER=NOFT
DO WHILE .T.
   IF FOUND() .AND. .NOT. EOF()
      IF REC_LOCK()
         REPL INV_STAT WITH 'CR'
      ENDIF
      UNLOCK
      CONTINUE
      LOOP
   ELSE
      EXIT
   ENDIF
ENDDO

SELE 5
LOCA FOR INV_NBER=NOFT
DO WHILE .T.
   IF FOUND() .AND. .NOT. EOF()
      IF REC_LOCK()
         REPL INV_STAT WITH 'CR'
      ENDIF
      UNLOCK
      CONTINUE
      LOOP
   ELSE
      EXIT
   ENDIF
ENDDO

SELE 6
LOCA FOR INV_NBER=NOFT
DO WHILE .T.
   IF FOUND() .AND. .NOT. EOF()
      IF REC_LOCK()
         REPL INV_STAT WITH 'CR'
      ENDIF
      UNLOCK
      CONTINUE
      LOOP
   ELSE
      EXIT
   ENDIF
ENDDO

